load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

package(default_visibility = ["//visibility:private"])

bool_flag(
    name = "multithreading",
    build_setting_default = False,
    visibility = ["//visibility:public"],
)

config_setting(
    name = "multithreading_on_windows",
    flag_values = {":multithreading": "true"},
    constraint_values = ["@platforms//os:windows"],
)

config_setting(
    name = "multithreading_enabled",
    flag_values = {":multithreading": "true"},
)

cc_binary(
    name = "lz4",
    srcs = [
        "bench.c",
        "bench.h",
        "lorem.c",
        "lorem.h",
        "lz4cli.c",
        "lz4conf.h",
        "lz4io.c",
        "lz4io.h",
        "platform.h",
        "threadpool.c",
        "threadpool.h",
        "timefn.c",
        "timefn.h",
        "util.c",
        "util.h",
    ],
    visibility = ["//visibility:public"],
    copts = select({
        ":multithreading_on_windows": ["-DLZ4IO_MULTITHREAD=1"],
        ":multithreading_enabled": [
            "-DLZ4IO_MULTITHREAD=1",
            "-pthread",
        ],
        "//conditions:default": ["-DLZ4IO_MULTITHREAD=0"],
    }),
    linkopts = select({
        ":multithreading_on_windows": [],
        ":multithreading_enabled": ["-pthread"],
        "//conditions:default": [],
    }),
    deps = ["//:lz4"],
)
